package com.yuneec.droneservice.command;

import com.yuneec.droneservice.request.IResponse;

import java.util.Arrays;

/**
 * 通过2.4G透传Payload给飞机
 * Created by gjw on 2017/3/27.
 */

public class SendPayload extends BaseCommand {

    public SendPayload(byte[] data) {
        super(MAV_RC_COMMAND.MAV_RC_CMD_SEND_PAYLOAD);
        this.data = data;
    }

    @Override
    public IResponse<byte[]> toResponse(byte[] data, int off, int len) {
        int code = data[off + 1] & 0xff;
        IResponse<byte[]> response = new IResponse(ids(), code);
        if (code == MAV_RC_ERROR_CODE.MAV_RC_ERR_SUCCESS) {
            byte[] param = Arrays.copyOfRange(data, off + 2, off + len);
            response.setParam(param);
        }
        return response;
    }

}
